{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>frame</th>\n",
       "      <th>track_id</th>\n",
       "      <th>type</th>\n",
       "      <th>truncated</th>\n",
       "      <th>occluded</th>\n",
       "      <th>alpha</th>\n",
       "      <th>bbox_left</th>\n",
       "      <th>bbox_top</th>\n",
       "      <th>bbox_right</th>\n",
       "      <th>bbox_bottom</th>\n",
       "      <th>height</th>\n",
       "      <th>width</th>\n",
       "      <th>length</th>\n",
       "      <th>pos_x</th>\n",
       "      <th>pos_y</th>\n",
       "      <th>pos_z</th>\n",
       "      <th>rot_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>DontCare</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-10.000000</td>\n",
       "      <td>219.310000</td>\n",
       "      <td>188.490000</td>\n",
       "      <td>245.500000</td>\n",
       "      <td>218.560000</td>\n",
       "      <td>-1000.000000</td>\n",
       "      <td>-1000.000000</td>\n",
       "      <td>-1000.000000</td>\n",
       "      <td>-10.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>DontCare</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-10.000000</td>\n",
       "      <td>47.560000</td>\n",
       "      <td>195.280000</td>\n",
       "      <td>115.480000</td>\n",
       "      <td>221.480000</td>\n",
       "      <td>-1000.000000</td>\n",
       "      <td>-1000.000000</td>\n",
       "      <td>-1000.000000</td>\n",
       "      <td>-10.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Van</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.793451</td>\n",
       "      <td>296.744956</td>\n",
       "      <td>161.752147</td>\n",
       "      <td>455.226042</td>\n",
       "      <td>292.372804</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.823255</td>\n",
       "      <td>4.433886</td>\n",
       "      <td>-4.552284</td>\n",
       "      <td>1.858523</td>\n",
       "      <td>13.410495</td>\n",
       "      <td>-2.115488</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Cyclist</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.936993</td>\n",
       "      <td>737.619499</td>\n",
       "      <td>161.531951</td>\n",
       "      <td>931.112229</td>\n",
       "      <td>374.000000</td>\n",
       "      <td>1.739063</td>\n",
       "      <td>0.824591</td>\n",
       "      <td>1.785241</td>\n",
       "      <td>1.640400</td>\n",
       "      <td>1.675660</td>\n",
       "      <td>5.776261</td>\n",
       "      <td>-1.675458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>Pedestrian</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-2.523309</td>\n",
       "      <td>1106.137292</td>\n",
       "      <td>166.576807</td>\n",
       "      <td>1204.470628</td>\n",
       "      <td>323.876144</td>\n",
       "      <td>1.714062</td>\n",
       "      <td>0.767881</td>\n",
       "      <td>0.972283</td>\n",
       "      <td>6.301919</td>\n",
       "      <td>1.652419</td>\n",
       "      <td>8.455685</td>\n",
       "      <td>-1.900245</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   frame  track_id        type  truncated  occluded      alpha    bbox_left  \\\n",
       "0      0        -1    DontCare         -1        -1 -10.000000   219.310000   \n",
       "1      0        -1    DontCare         -1        -1 -10.000000    47.560000   \n",
       "2      0         0         Van          0         0  -1.793451   296.744956   \n",
       "3      0         1     Cyclist          0         0  -1.936993   737.619499   \n",
       "4      0         2  Pedestrian          0         0  -2.523309  1106.137292   \n",
       "\n",
       "     bbox_top   bbox_right  bbox_bottom       height        width  \\\n",
       "0  188.490000   245.500000   218.560000 -1000.000000 -1000.000000   \n",
       "1  195.280000   115.480000   221.480000 -1000.000000 -1000.000000   \n",
       "2  161.752147   455.226042   292.372804     2.000000     1.823255   \n",
       "3  161.531951   931.112229   374.000000     1.739063     0.824591   \n",
       "4  166.576807  1204.470628   323.876144     1.714062     0.767881   \n",
       "\n",
       "        length      pos_x     pos_y      pos_z     rot_y  \n",
       "0 -1000.000000 -10.000000 -1.000000  -1.000000 -1.000000  \n",
       "1 -1000.000000 -10.000000 -1.000000  -1.000000 -1.000000  \n",
       "2     4.433886  -4.552284  1.858523  13.410495 -2.115488  \n",
       "3     1.785241   1.640400  1.675660   5.776261 -1.675458  \n",
       "4     0.972283   6.301919  1.652419   8.455685 -1.900245  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\"\"\"\n",
    "   1    frame        Frame within the sequence where the object appearers\n",
    "   1    track id     Unique tracking id of this object within this sequence\n",
    "   1    type         Describes the type of object: 'Car', 'Van', 'Truck',\n",
    "                     'Pedestrian', 'Person_sitting', 'Cyclist', 'Tram',\n",
    "                     'Misc' or 'DontCare'\n",
    "   1    truncated    Float from 0 (non-truncated) to 1 (truncated), where\n",
    "                     truncated refers to the object leaving image boundaries.\n",
    "\t\t     Truncation 2 indicates an ignored object (in particular\n",
    "\t\t     in the beginning or end of a track) introduced by manual\n",
    "\t\t     labeling.\n",
    "   1    occluded     Integer (0,1,2,3) indicating occlusion state:\n",
    "                     0 = fully visible, 1 = partly occluded\n",
    "                     2 = largely occluded, 3 = unknown\n",
    "   1    alpha        Observation angle of object, ranging [-pi..pi]\n",
    "   4    bbox         2D bounding box of object in the image (0-based index):\n",
    "                     contains left, top, right, bottom pixel coordinates\n",
    "   3    dimensions   3D object dimensions: height, width, length (in meters)\n",
    "   3    location     3D object location x,y,z in camera coordinates (in meters)\n",
    "   1    rotation_y   Rotation ry around Y-axis in camera coordinates [-pi..pi]\n",
    "   1    score        Only for results: Float, indicating confidence in\n",
    "                     detection, needed for p/r curves, higher is better.\n",
    "\"\"\"\n",
    "COLUMN_NAMES = ['frame','track_id','type','truncated','occluded','alpha','bbox_left','bbox_top',\n",
    "               'bbox_right','bbox_bottom','height','width','length','pos_x','pos_y','pos_z','rot_y']\n",
    "df = pd.read_csv('/home/jony/data/kitti/data_tracking_label_2/training/label_02/0000.txt', header=None, sep=' ')\n",
    "df.columns = COLUMN_NAMES\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       False\n",
       "1       False\n",
       "2        True\n",
       "3       False\n",
       "4       False\n",
       "        ...  \n",
       "1084    False\n",
       "1085    False\n",
       "1086    False\n",
       "1087    False\n",
       "1088    False\n",
       "Name: type, Length: 1089, dtype: bool"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 判断类别是否是车\n",
    "df.type.isin(['Truck','Van','Tram'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>frame</th>\n",
       "      <th>track_id</th>\n",
       "      <th>type</th>\n",
       "      <th>truncated</th>\n",
       "      <th>occluded</th>\n",
       "      <th>alpha</th>\n",
       "      <th>bbox_left</th>\n",
       "      <th>bbox_top</th>\n",
       "      <th>bbox_right</th>\n",
       "      <th>bbox_bottom</th>\n",
       "      <th>height</th>\n",
       "      <th>width</th>\n",
       "      <th>length</th>\n",
       "      <th>pos_x</th>\n",
       "      <th>pos_y</th>\n",
       "      <th>pos_z</th>\n",
       "      <th>rot_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>DontCare</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-10.000000</td>\n",
       "      <td>219.310000</td>\n",
       "      <td>188.490000</td>\n",
       "      <td>245.500000</td>\n",
       "      <td>218.560000</td>\n",
       "      <td>-1000.000000</td>\n",
       "      <td>-1000.000000</td>\n",
       "      <td>-1000.000000</td>\n",
       "      <td>-10.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>DontCare</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-10.000000</td>\n",
       "      <td>47.560000</td>\n",
       "      <td>195.280000</td>\n",
       "      <td>115.480000</td>\n",
       "      <td>221.480000</td>\n",
       "      <td>-1000.000000</td>\n",
       "      <td>-1000.000000</td>\n",
       "      <td>-1000.000000</td>\n",
       "      <td>-10.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Car</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.793451</td>\n",
       "      <td>296.744956</td>\n",
       "      <td>161.752147</td>\n",
       "      <td>455.226042</td>\n",
       "      <td>292.372804</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.823255</td>\n",
       "      <td>4.433886</td>\n",
       "      <td>-4.552284</td>\n",
       "      <td>1.858523</td>\n",
       "      <td>13.410495</td>\n",
       "      <td>-2.115488</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Cyclist</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.936993</td>\n",
       "      <td>737.619499</td>\n",
       "      <td>161.531951</td>\n",
       "      <td>931.112229</td>\n",
       "      <td>374.000000</td>\n",
       "      <td>1.739063</td>\n",
       "      <td>0.824591</td>\n",
       "      <td>1.785241</td>\n",
       "      <td>1.640400</td>\n",
       "      <td>1.675660</td>\n",
       "      <td>5.776261</td>\n",
       "      <td>-1.675458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>Pedestrian</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-2.523309</td>\n",
       "      <td>1106.137292</td>\n",
       "      <td>166.576807</td>\n",
       "      <td>1204.470628</td>\n",
       "      <td>323.876144</td>\n",
       "      <td>1.714062</td>\n",
       "      <td>0.767881</td>\n",
       "      <td>0.972283</td>\n",
       "      <td>6.301919</td>\n",
       "      <td>1.652419</td>\n",
       "      <td>8.455685</td>\n",
       "      <td>-1.900245</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1084</th>\n",
       "      <td>153</td>\n",
       "      <td>10</td>\n",
       "      <td>Car</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>-1.818856</td>\n",
       "      <td>680.294919</td>\n",
       "      <td>177.511028</td>\n",
       "      <td>842.313244</td>\n",
       "      <td>284.070033</td>\n",
       "      <td>1.524000</td>\n",
       "      <td>1.728591</td>\n",
       "      <td>3.894227</td>\n",
       "      <td>2.353367</td>\n",
       "      <td>1.622590</td>\n",
       "      <td>12.436503</td>\n",
       "      <td>-1.637280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1085</th>\n",
       "      <td>153</td>\n",
       "      <td>11</td>\n",
       "      <td>Car</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1.864481</td>\n",
       "      <td>245.920800</td>\n",
       "      <td>194.456182</td>\n",
       "      <td>394.817829</td>\n",
       "      <td>286.444967</td>\n",
       "      <td>1.444000</td>\n",
       "      <td>1.595116</td>\n",
       "      <td>3.791789</td>\n",
       "      <td>-5.458963</td>\n",
       "      <td>1.908188</td>\n",
       "      <td>13.979427</td>\n",
       "      <td>1.497916</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1086</th>\n",
       "      <td>153</td>\n",
       "      <td>12</td>\n",
       "      <td>Pedestrian</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.826456</td>\n",
       "      <td>1185.199080</td>\n",
       "      <td>151.165841</td>\n",
       "      <td>1241.000000</td>\n",
       "      <td>348.552707</td>\n",
       "      <td>1.688000</td>\n",
       "      <td>0.800000</td>\n",
       "      <td>0.884000</td>\n",
       "      <td>5.739732</td>\n",
       "      <td>1.500532</td>\n",
       "      <td>6.279632</td>\n",
       "      <td>1.543272</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1087</th>\n",
       "      <td>153</td>\n",
       "      <td>13</td>\n",
       "      <td>Car</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.773993</td>\n",
       "      <td>344.361560</td>\n",
       "      <td>188.772369</td>\n",
       "      <td>430.531955</td>\n",
       "      <td>248.482384</td>\n",
       "      <td>1.422414</td>\n",
       "      <td>1.512803</td>\n",
       "      <td>3.707634</td>\n",
       "      <td>-6.033258</td>\n",
       "      <td>1.888008</td>\n",
       "      <td>19.788795</td>\n",
       "      <td>1.481180</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1088</th>\n",
       "      <td>153</td>\n",
       "      <td>14</td>\n",
       "      <td>Car</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>-1.728662</td>\n",
       "      <td>652.362288</td>\n",
       "      <td>183.789605</td>\n",
       "      <td>737.478033</td>\n",
       "      <td>246.613864</td>\n",
       "      <td>1.365956</td>\n",
       "      <td>1.508586</td>\n",
       "      <td>3.485915</td>\n",
       "      <td>1.955738</td>\n",
       "      <td>1.651867</td>\n",
       "      <td>17.818612</td>\n",
       "      <td>-1.622048</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1089 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      frame  track_id        type  truncated  occluded      alpha  \\\n",
       "0         0        -1    DontCare         -1        -1 -10.000000   \n",
       "1         0        -1    DontCare         -1        -1 -10.000000   \n",
       "2         0         0         Car          0         0  -1.793451   \n",
       "3         0         1     Cyclist          0         0  -1.936993   \n",
       "4         0         2  Pedestrian          0         0  -2.523309   \n",
       "...     ...       ...         ...        ...       ...        ...   \n",
       "1084    153        10         Car          0         2  -1.818856   \n",
       "1085    153        11         Car          0         2   1.864481   \n",
       "1086    153        12  Pedestrian          1         0   0.826456   \n",
       "1087    153        13         Car          0         0   1.773993   \n",
       "1088    153        14         Car          0         2  -1.728662   \n",
       "\n",
       "        bbox_left    bbox_top   bbox_right  bbox_bottom       height  \\\n",
       "0      219.310000  188.490000   245.500000   218.560000 -1000.000000   \n",
       "1       47.560000  195.280000   115.480000   221.480000 -1000.000000   \n",
       "2      296.744956  161.752147   455.226042   292.372804     2.000000   \n",
       "3      737.619499  161.531951   931.112229   374.000000     1.739063   \n",
       "4     1106.137292  166.576807  1204.470628   323.876144     1.714062   \n",
       "...           ...         ...          ...          ...          ...   \n",
       "1084   680.294919  177.511028   842.313244   284.070033     1.524000   \n",
       "1085   245.920800  194.456182   394.817829   286.444967     1.444000   \n",
       "1086  1185.199080  151.165841  1241.000000   348.552707     1.688000   \n",
       "1087   344.361560  188.772369   430.531955   248.482384     1.422414   \n",
       "1088   652.362288  183.789605   737.478033   246.613864     1.365956   \n",
       "\n",
       "            width       length      pos_x     pos_y      pos_z     rot_y  \n",
       "0    -1000.000000 -1000.000000 -10.000000 -1.000000  -1.000000 -1.000000  \n",
       "1    -1000.000000 -1000.000000 -10.000000 -1.000000  -1.000000 -1.000000  \n",
       "2        1.823255     4.433886  -4.552284  1.858523  13.410495 -2.115488  \n",
       "3        0.824591     1.785241   1.640400  1.675660   5.776261 -1.675458  \n",
       "4        0.767881     0.972283   6.301919  1.652419   8.455685 -1.900245  \n",
       "...           ...          ...        ...       ...        ...       ...  \n",
       "1084     1.728591     3.894227   2.353367  1.622590  12.436503 -1.637280  \n",
       "1085     1.595116     3.791789  -5.458963  1.908188  13.979427  1.497916  \n",
       "1086     0.800000     0.884000   5.739732  1.500532   6.279632  1.543272  \n",
       "1087     1.512803     3.707634  -6.033258  1.888008  19.788795  1.481180  \n",
       "1088     1.508586     3.485915   1.955738  1.651867  17.818612 -1.622048  \n",
       "\n",
       "[1089 rows x 17 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将上述三类统一指定为Car类\n",
    "df.loc[df.type.isin(['Truck','Van','Tram']), 'type'] = 'Car'\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>frame</th>\n",
       "      <th>track_id</th>\n",
       "      <th>type</th>\n",
       "      <th>truncated</th>\n",
       "      <th>occluded</th>\n",
       "      <th>alpha</th>\n",
       "      <th>bbox_left</th>\n",
       "      <th>bbox_top</th>\n",
       "      <th>bbox_right</th>\n",
       "      <th>bbox_bottom</th>\n",
       "      <th>height</th>\n",
       "      <th>width</th>\n",
       "      <th>length</th>\n",
       "      <th>pos_x</th>\n",
       "      <th>pos_y</th>\n",
       "      <th>pos_z</th>\n",
       "      <th>rot_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Car</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.793451</td>\n",
       "      <td>296.744956</td>\n",
       "      <td>161.752147</td>\n",
       "      <td>455.226042</td>\n",
       "      <td>292.372804</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.823255</td>\n",
       "      <td>4.433886</td>\n",
       "      <td>-4.552284</td>\n",
       "      <td>1.858523</td>\n",
       "      <td>13.410495</td>\n",
       "      <td>-2.115488</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Cyclist</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.936993</td>\n",
       "      <td>737.619499</td>\n",
       "      <td>161.531951</td>\n",
       "      <td>931.112229</td>\n",
       "      <td>374.000000</td>\n",
       "      <td>1.739063</td>\n",
       "      <td>0.824591</td>\n",
       "      <td>1.785241</td>\n",
       "      <td>1.640400</td>\n",
       "      <td>1.675660</td>\n",
       "      <td>5.776261</td>\n",
       "      <td>-1.675458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>Pedestrian</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-2.523309</td>\n",
       "      <td>1106.137292</td>\n",
       "      <td>166.576807</td>\n",
       "      <td>1204.470628</td>\n",
       "      <td>323.876144</td>\n",
       "      <td>1.714062</td>\n",
       "      <td>0.767881</td>\n",
       "      <td>0.972283</td>\n",
       "      <td>6.301919</td>\n",
       "      <td>1.652419</td>\n",
       "      <td>8.455685</td>\n",
       "      <td>-1.900245</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>Car</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.796862</td>\n",
       "      <td>294.898777</td>\n",
       "      <td>156.024256</td>\n",
       "      <td>452.199718</td>\n",
       "      <td>284.621269</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.823255</td>\n",
       "      <td>4.433886</td>\n",
       "      <td>-4.650955</td>\n",
       "      <td>1.766774</td>\n",
       "      <td>13.581085</td>\n",
       "      <td>-2.121565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Cyclist</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.935205</td>\n",
       "      <td>745.017137</td>\n",
       "      <td>156.393157</td>\n",
       "      <td>938.839722</td>\n",
       "      <td>374.000000</td>\n",
       "      <td>1.739063</td>\n",
       "      <td>0.824591</td>\n",
       "      <td>1.785241</td>\n",
       "      <td>1.700640</td>\n",
       "      <td>1.640419</td>\n",
       "      <td>5.778596</td>\n",
       "      <td>-1.664456</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1084</th>\n",
       "      <td>153</td>\n",
       "      <td>10</td>\n",
       "      <td>Car</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>-1.818856</td>\n",
       "      <td>680.294919</td>\n",
       "      <td>177.511028</td>\n",
       "      <td>842.313244</td>\n",
       "      <td>284.070033</td>\n",
       "      <td>1.524000</td>\n",
       "      <td>1.728591</td>\n",
       "      <td>3.894227</td>\n",
       "      <td>2.353367</td>\n",
       "      <td>1.622590</td>\n",
       "      <td>12.436503</td>\n",
       "      <td>-1.637280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1085</th>\n",
       "      <td>153</td>\n",
       "      <td>11</td>\n",
       "      <td>Car</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1.864481</td>\n",
       "      <td>245.920800</td>\n",
       "      <td>194.456182</td>\n",
       "      <td>394.817829</td>\n",
       "      <td>286.444967</td>\n",
       "      <td>1.444000</td>\n",
       "      <td>1.595116</td>\n",
       "      <td>3.791789</td>\n",
       "      <td>-5.458963</td>\n",
       "      <td>1.908188</td>\n",
       "      <td>13.979427</td>\n",
       "      <td>1.497916</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1086</th>\n",
       "      <td>153</td>\n",
       "      <td>12</td>\n",
       "      <td>Pedestrian</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.826456</td>\n",
       "      <td>1185.199080</td>\n",
       "      <td>151.165841</td>\n",
       "      <td>1241.000000</td>\n",
       "      <td>348.552707</td>\n",
       "      <td>1.688000</td>\n",
       "      <td>0.800000</td>\n",
       "      <td>0.884000</td>\n",
       "      <td>5.739732</td>\n",
       "      <td>1.500532</td>\n",
       "      <td>6.279632</td>\n",
       "      <td>1.543272</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1087</th>\n",
       "      <td>153</td>\n",
       "      <td>13</td>\n",
       "      <td>Car</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.773993</td>\n",
       "      <td>344.361560</td>\n",
       "      <td>188.772369</td>\n",
       "      <td>430.531955</td>\n",
       "      <td>248.482384</td>\n",
       "      <td>1.422414</td>\n",
       "      <td>1.512803</td>\n",
       "      <td>3.707634</td>\n",
       "      <td>-6.033258</td>\n",
       "      <td>1.888008</td>\n",
       "      <td>19.788795</td>\n",
       "      <td>1.481180</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1088</th>\n",
       "      <td>153</td>\n",
       "      <td>14</td>\n",
       "      <td>Car</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>-1.728662</td>\n",
       "      <td>652.362288</td>\n",
       "      <td>183.789605</td>\n",
       "      <td>737.478033</td>\n",
       "      <td>246.613864</td>\n",
       "      <td>1.365956</td>\n",
       "      <td>1.508586</td>\n",
       "      <td>3.485915</td>\n",
       "      <td>1.955738</td>\n",
       "      <td>1.651867</td>\n",
       "      <td>17.818612</td>\n",
       "      <td>-1.622048</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>711 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      frame  track_id        type  truncated  occluded     alpha    bbox_left  \\\n",
       "2         0         0         Car          0         0 -1.793451   296.744956   \n",
       "3         0         1     Cyclist          0         0 -1.936993   737.619499   \n",
       "4         0         2  Pedestrian          0         0 -2.523309  1106.137292   \n",
       "7         1         0         Car          0         0 -1.796862   294.898777   \n",
       "8         1         1     Cyclist          0         0 -1.935205   745.017137   \n",
       "...     ...       ...         ...        ...       ...       ...          ...   \n",
       "1084    153        10         Car          0         2 -1.818856   680.294919   \n",
       "1085    153        11         Car          0         2  1.864481   245.920800   \n",
       "1086    153        12  Pedestrian          1         0  0.826456  1185.199080   \n",
       "1087    153        13         Car          0         0  1.773993   344.361560   \n",
       "1088    153        14         Car          0         2 -1.728662   652.362288   \n",
       "\n",
       "        bbox_top   bbox_right  bbox_bottom    height     width    length  \\\n",
       "2     161.752147   455.226042   292.372804  2.000000  1.823255  4.433886   \n",
       "3     161.531951   931.112229   374.000000  1.739063  0.824591  1.785241   \n",
       "4     166.576807  1204.470628   323.876144  1.714062  0.767881  0.972283   \n",
       "7     156.024256   452.199718   284.621269  2.000000  1.823255  4.433886   \n",
       "8     156.393157   938.839722   374.000000  1.739063  0.824591  1.785241   \n",
       "...          ...          ...          ...       ...       ...       ...   \n",
       "1084  177.511028   842.313244   284.070033  1.524000  1.728591  3.894227   \n",
       "1085  194.456182   394.817829   286.444967  1.444000  1.595116  3.791789   \n",
       "1086  151.165841  1241.000000   348.552707  1.688000  0.800000  0.884000   \n",
       "1087  188.772369   430.531955   248.482384  1.422414  1.512803  3.707634   \n",
       "1088  183.789605   737.478033   246.613864  1.365956  1.508586  3.485915   \n",
       "\n",
       "         pos_x     pos_y      pos_z     rot_y  \n",
       "2    -4.552284  1.858523  13.410495 -2.115488  \n",
       "3     1.640400  1.675660   5.776261 -1.675458  \n",
       "4     6.301919  1.652419   8.455685 -1.900245  \n",
       "7    -4.650955  1.766774  13.581085 -2.121565  \n",
       "8     1.700640  1.640419   5.778596 -1.664456  \n",
       "...        ...       ...        ...       ...  \n",
       "1084  2.353367  1.622590  12.436503 -1.637280  \n",
       "1085 -5.458963  1.908188  13.979427  1.497916  \n",
       "1086  5.739732  1.500532   6.279632  1.543272  \n",
       "1087 -6.033258  1.888008  19.788795  1.481180  \n",
       "1088  1.955738  1.651867  17.818612 -1.622048  \n",
       "\n",
       "[711 rows x 17 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出需要的类别\n",
    "df = df[df.type.isin(['Car','Pedestrian','Cyclist'])]\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "296.744956"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 提取第一行的bbox_left的信息\n",
    "df.loc[2,'bbox_left']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([296.744956, 161.752147, 455.226042, 292.372804], dtype=object)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "box = np.array(df.loc[2,['bbox_left','bbox_top','bbox_right','bbox_bottom']])\n",
    "box"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "\n",
    "image = cv2.imread('/home/jony/data/kitti/RawData/2011_09_26/2011_09_26_drive_0005_sync/image_02/data/0000000000.png')\n",
    "\n",
    "top_left = int(box[0]), int(box[1])\n",
    "bottom_right = int(box[2]), int(box[3])\n",
    "\n",
    "# cv2.rectangle(图片位置,左上角坐标,右下角坐标,颜色,线宽)\n",
    "cv2.rectangle(image, top_left, bottom_right, (255, 255, 0), 2)\n",
    "\n",
    "# 显示图片\n",
    "cv2.imshow(\"image\", image)\n",
    "cv2.waitKey(0)\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>frame</th>\n",
       "      <th>track</th>\n",
       "      <th>type</th>\n",
       "      <th>truncated</th>\n",
       "      <th>occluded</th>\n",
       "      <th>alpha</th>\n",
       "      <th>bbox_left</th>\n",
       "      <th>bbox_top</th>\n",
       "      <th>bbox_right</th>\n",
       "      <th>bbox_bottom</th>\n",
       "      <th>height</th>\n",
       "      <th>width</th>\n",
       "      <th>length</th>\n",
       "      <th>pos_x</th>\n",
       "      <th>pos_y</th>\n",
       "      <th>pos_z</th>\n",
       "      <th>rot_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>Car</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.793451</td>\n",
       "      <td>296.744956</td>\n",
       "      <td>161.752147</td>\n",
       "      <td>455.226042</td>\n",
       "      <td>292.372804</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.823255</td>\n",
       "      <td>4.433886</td>\n",
       "      <td>-4.552284</td>\n",
       "      <td>1.858523</td>\n",
       "      <td>13.410495</td>\n",
       "      <td>-2.115488</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Cyclist</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1.936993</td>\n",
       "      <td>737.619499</td>\n",
       "      <td>161.531951</td>\n",
       "      <td>931.112229</td>\n",
       "      <td>374.000000</td>\n",
       "      <td>1.739063</td>\n",
       "      <td>0.824591</td>\n",
       "      <td>1.785241</td>\n",
       "      <td>1.640400</td>\n",
       "      <td>1.675660</td>\n",
       "      <td>5.776261</td>\n",
       "      <td>-1.675458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>Pedestrian</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-2.523309</td>\n",
       "      <td>1106.137292</td>\n",
       "      <td>166.576807</td>\n",
       "      <td>1204.470628</td>\n",
       "      <td>323.876144</td>\n",
       "      <td>1.714062</td>\n",
       "      <td>0.767881</td>\n",
       "      <td>0.972283</td>\n",
       "      <td>6.301919</td>\n",
       "      <td>1.652419</td>\n",
       "      <td>8.455685</td>\n",
       "      <td>-1.900245</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   frame  track        type  truncated  occluded     alpha    bbox_left  \\\n",
       "2      0      0         Car          0         0 -1.793451   296.744956   \n",
       "3      0      1     Cyclist          0         0 -1.936993   737.619499   \n",
       "4      0      2  Pedestrian          0         0 -2.523309  1106.137292   \n",
       "\n",
       "     bbox_top   bbox_right  bbox_bottom    height     width    length  \\\n",
       "2  161.752147   455.226042   292.372804  2.000000  1.823255  4.433886   \n",
       "3  161.531951   931.112229   374.000000  1.739063  0.824591  1.785241   \n",
       "4  166.576807  1204.470628   323.876144  1.714062  0.767881  0.972283   \n",
       "\n",
       "      pos_x     pos_y      pos_z     rot_y  \n",
       "2 -4.552284  1.858523  13.410495 -2.115488  \n",
       "3  1.640400  1.675660   5.776261 -1.675458  \n",
       "4  6.301919  1.652419   8.455685 -1.900245  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出第一张图中的所有类别信息\n",
    "df[df.frame==0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 296.744956,  161.752147,  455.226042,  292.372804],\n",
       "       [ 737.619499,  161.531951,  931.112229,  374.      ],\n",
       "       [1106.137292,  166.576807, 1204.470628,  323.876144]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(df[df.frame==0][['bbox_left','bbox_top','bbox_right','bbox_bottom']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "DETECTION_CLOLR_DICT = {'Car':(255,255,0), 'Pedestrian':(0,226,255), 'Cyclist':(141, 40, 255)}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "\n",
    "frame = 120\n",
    "\n",
    "image = cv2.imread('/home/jony/data/kitti/RawData/2011_09_26/2011_09_26_drive_0005_sync/image_02/data/%010d.png'%frame)\n",
    "\n",
    "boxes = np.array(df[df.frame==frame][['bbox_left','bbox_top','bbox_right','bbox_bottom']])\n",
    "types = np.array(df[df.frame==frame]['type'])\n",
    "for typ, box in zip(types, boxes):\n",
    "    top_left = int(box[0]), int(box[1])\n",
    "    bottom_right = int(box[2]), int(box[3])\n",
    "\n",
    "    # cv2.rectangle(图片位置,左上角坐标,右下角坐标,颜色,线宽)\n",
    "    cv2.rectangle(image, top_left, bottom_right, DETECTION_CLOLR_DICT[typ], 2)\n",
    "\n",
    "# 显示图片\n",
    "cv2.imshow(\"image\", image)\n",
    "cv2.waitKey(0)\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "boxes = np.array(df[df.frame==0][['bbox_left','bbox_top','bbox_right','bbox_bottom']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "types = np.array(df[df.frame==0]['type'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 296.744956,  161.752147,  455.226042,  292.372804],\n",
       "       [ 737.619499,  161.531951,  931.112229,  374.      ],\n",
       "       [1106.137292,  166.576807, 1204.470628,  323.876144]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "boxes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Car', 'Cyclist', 'Pedestrian'], dtype=object)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "types"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('Car', array([296.744956, 161.752147, 455.226042, 292.372804])),\n",
       " ('Cyclist', array([737.619499, 161.531951, 931.112229, 374.      ])),\n",
       " ('Pedestrian', array([1106.137292,  166.576807, 1204.470628,  323.876144]))]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ziped = zip(types, boxes)\n",
    "list(ziped)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
